﻿using Bll;
using Help;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Myproject.BSM.Ashx.PcChannel
{
    /// <summary>
    /// GoodsEdit 的摘要说明
    /// </summary>
    public class GoodsEdit : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string id = context.Request.Form["pc_Channel_GoodsEdit_GoodsId"];
            string name = context.Request.Form["pc_Channel_GoodsEdit_name"];
            string othername = context.Request.Form["pc_Channel_GoodsEdit_othername"];
            string ename = context.Request.Form["pc_Channel_GoodsEdit_ename"];
            string url = context.Request.Form["doc_pic"];
            string pid = context.Request.Form["pc_Channel_GoodsEdit_GoodsClassId"];
            string cent = context.Request.Form["pc_Channel_GoodsEdit_text"];
            if (id == "0")
            {
                GoodsModel model = new GoodsModel();
                model.Name = name;
                model.OtherName = othername;
                model.EnName = ename;
                model.GoodsClassID = int.Parse(pid);
                model.GoodsContent = cent;
                model.Show = true;
                model.Url = url;
                model.WebSlideID = 0;
                
                if (new GoodsBLL().Add(model) > 0)
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "添加产品成功！", "pc_channel_GoodsList", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "添加产品失败！", "pc_channel_GoodsList", "", "", true, "", ""));
                }
            }
            else
            {
                GoodsModel model = new GoodsBLL().GetModel(int.Parse(id));
                model.Name = name;
                model.OtherName = othername;
                model.EnName = ename;
                model.GoodsClassID = int.Parse(pid);
                model.GoodsContent = cent;
                model.Show = true;
                model.Url = url;
                model.WebSlideID = 0;
                if (new GoodsBLL().Update(model))
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(200, "修改产品成功！", "pc_channel_GoodsList", "", "", true, "", ""));
                }
                else
                {
                    context.Response.Write(ReturnJsonHelp.BJUIajaxJson(300, "修改产品失败！", "pc_channel_GoodsList", "", "", true, "", ""));
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}